//
//  STOrderCommentVC.m
//  YiYueHairdresser
//
//  Created by 路人甲 on 2018/11/7.
//  Copyright © 2018年 YuYiLian. All rights reserved.
//

#import "STOrderCommentVC.h"
#import "STOrderCommentView.h"

@interface STOrderCommentVC ()<STOrderCommentViewDelegate>{
    STOrderCommentView * commentView;
    STCommentInfoModel * orderCommentData;
    
}

@end

@implementation STOrderCommentVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"查看评价";
    [self wr_setNavBarTintColor:[UIColor blackColor]];
    
    [self loadOrderCommentView];
    [self loadOrderCommentData];
    [self loadHairEvaluateData];
}

-(void)loadOrderCommentData{
    [STMainPageService getOrderCommentWithOrderId:[self.detailModel.orderId longValue] completion:^(id result, NSError *error) {
        if(error){
            [ZYHCommonMethod showError:error];
        }
        orderCommentData = [STCommentInfoModel modelWithJSON:result];
        commentView.orderCommentData = orderCommentData;
        [commentView setOrderCommentsListView];
    }];
}


-(void)loadHairEvaluateData{
    [STMainPageService getHairerEvaluate:[self.detailModel.stylistId longValue] completion:^(id result, NSError *error) {
        if(error){
            [ZYHCommonMethod showError:error];
        }
        STDoorCommonModel * evaluate = [STDoorCommonModel modelWithJSON:result];
        commentView.totalScore = evaluate;
        [commentView setOrderCommentsListView];
    }];
}

- (void)loadOrderCommentView {
    if(!commentView){
        commentView = [[STOrderCommentView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        commentView.delegate = self;
        commentView.detailModel = self.detailModel;
        [commentView setOrderCommentsListView];
        [self.view addSubview:commentView];
    }
        
}

-(void)orderCommentsView:(STOrderCommentView *)view indexpath:(NSIndexPath *)indexPath replayCommentText:(NSString *)replayStr{
    [STMainPageService replayDoorCommentWithCommentId:orderCommentData.objectId context:replayStr completion:^(id result, NSError *error) {
        if (error) {
            [ZYHCommonMethod showError:error];
        }else{
            [ZYHCommonMethod showSuccess:@"回复成功"];
            [self loadOrderCommentData];
        }
    }];
}


@end
